package day17.tarena.GUI;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TestShowPicture implements ActionListener{
	CardLayout cl = new CardLayout();
	JPanel jp1 = new JPanel();
	Timer t = new Timer(100,this);
	public void actionPerformed(ActionEvent e){
		String comm = e.getActionCommand();
		if("First".equals(comm)){
			cl.first(jp1);
		}else if("Last".equals(comm)){
			cl.last(jp1);
		}else if("Next".equals(comm)){
			cl.next(jp1);
		}else if("previous".equals(comm)){
			cl.previous(jp1);
		}else if("Start".equals(comm)){
			t.start();
		}else if("Stop".equals(comm)){
			t.stop();
		}else{
			cl.next(jp1);
		}
	}		//javax.swing.Timer类
	public TestShowPicture(){
		JFrame jf = new JFrame("My Frist");

		String[] jbLab = {"First","Last","Next","Previous","Start","Stop"};
		String[] iconLab = {"1.jpg","2.jpg","3.jpg","4.jpg","5.jpg"};
		JPanel jp2 = new JPanel();
		jp1.setLayout(cl);
		for(int i=0; i<iconLab.length; i++){
			JLabel jl = new JLabel(new ImageIcon("/home/hfsd0909/Picture/" + iconLab[i]));
			jp1.add(jl,""+i);
		}
		for(int i=0; i<jbLab.length; i++){
			JButton jb = new JButton(jbLab[i]);
			jb.addActionListener(this);
			jp2.add(jb);
		}
	
		jf.add(jp1);
		jf.add(jp2,BorderLayout.SOUTH);
		jf.setLocation(300,200);
		jf.pack();
		jf.setVisible(true);
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	
	}
	
	public static void main(String[] args) {
		new TestShowPicture();
	}
}
